<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>灵犀智苑 - 注册</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        :root {
            --primary: #4361ee;
            --primary-light: #5e72e4;
            --secondary: #4cc9f0;
            --accent: #e67e22;
            --light: #ecf0f1;
            --dark: #34495e;
            --darker: #2c3e50;
            --text: #2c3e50;
            --text-light: #7f8c8d;
            --glass: rgba(255, 255, 255, 0.2);
            --border: rgba(255, 255, 255, 0.3);
            --shadow: 0 8px 32px rgba(31, 38, 135, 0.15);
            --transition: all 0.3s ease;
            --error: #e74c3c;
            --success: #2ecc71;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4e7eb 100%);
            color: var(--text);
            min-height: 100vh;
            overflow-x: hidden;
        }

        .background-blur {
            position: fixed;
            top: -50px;
            left: -50px;
            right: -50px;
            bottom: -50px;
            background: url('');
            filter: blur(40px);
            z-index: -1;
        }

        /* 玻璃拟态效果 */
        .glass {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            border: 1px solid var(--border);
            box-shadow: var(--shadow);
            border-radius: 20px;
            overflow: hidden;
            transition: var(--transition);
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 0 2rem;
        }

        /* 导航栏 */
        header {
            padding: 1rem 0;
        }

        .navbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem 2rem;
            position: relative;
            z-index: 100;
        }

        .logo {
            display: flex;
            align-items: center;
            font-size: 1.8rem;
            font-weight: 700;
            background: linear-gradient(90deg, var(--primary), var(--accent));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .logo-icon {
            margin-right: 10px;
            animation: float 3s ease-in-out infinite;
        }

        .nav-links {
            list-style: none;
            display: flex;
            gap: 2rem;
        }

        .nav-links a {
            color: var(--darker);
            text-decoration: none;
            font-weight: 500;
            padding: 8px 0;
            position: relative;
            transition: var(--transition);
        }

        .nav-links a:after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: 0;
            left: 0;
            background: var(--primary);
            transition: var(--transition);
        }

        .nav-links a:hover:after,
        .nav-links a.active:after {
            width: 100%;
        }

        .nav-links a.active {
            color: var(--primary);
        }

        .cta-buttons {
            display: flex;
            gap: 1rem;
        }

        .btn {
            padding: 0.7rem 1.5rem;
            border-radius: 12px;
            border: none;
            cursor: pointer;
            font-weight: 500;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 1rem;
        }

        .btn-login {
            background: transparent;
            color: var(--darker);
            border: 1px solid var(--border);
        }

        .btn-login:hover {
            background: rgba(255, 255, 255, 0.2);
            transform: translateY(-2px);
        }

        .btn-signup {
            background: linear-gradient(90deg, var(--primary), var(--secondary));
            color: white;
            box-shadow: 0 4px 15px rgba(67, 97, 238, 0.3);
        }

        .btn-signup:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(67, 97, 238, 0.4);
        }

        /* 注册表单样式 */
        .register-container {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: calc(100vh - 100px);
            padding: 2rem;
        }

        .register-card {
            width: 100%;
            max-width: 500px;
            padding: 2.5rem;
        }

        .register-header {
            text-align: center;
            margin-bottom: 2.5rem;
        }

        .register-header h1 {
            font-size: 2.5rem;
            font-weight: 700;
            margin-bottom: 0.5rem;
            background: linear-gradient(90deg, var(--primary), var(--accent));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .register-header p {
            font-size: 1.1rem;
            color: var(--text-light);
        }

        .form-group {
            margin-bottom: 1.5rem;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 600;
            color: var(--darker);
            font-size: 1rem;
        }

        .input-with-icon {
            position: relative;
        }

        .input-with-icon i {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--primary);
            font-size: 1.1rem;
        }

        .form-control {
            width: 100%;
            padding: 0.9rem 0.9rem 0.9rem 45px;
            border: 1px solid #d1d9e6;
            border-radius: 12px;
            font-size: 1rem;
            transition: var(--transition);
            background-color: rgba(255, 255, 255, 0.5);
            box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.05);
        }

        .form-control:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
            outline: none;
            background-color: white;
        }

        .password-strength {
            display: flex;
            margin-top: 10px;
            gap: 5px;
        }

        .strength-bar {
            flex: 1;
            height: 6px;
            background: #e9ecef;
            border-radius: 3px;
            transition: var(--transition);
        }

        .strength-text {
            font-size: 0.85rem;
            margin-top: 5px;
            color: var(--text-light);
            font-weight: 500;
        }

        .error-message {
            color: var(--error);
            font-size: 0.9rem;
            margin-top: 8px;
            display: none;
        }

        .terms {
            display: flex;
            align-items: flex-start;
            margin-bottom: 1.5rem;
        }

        .terms input {
            margin-top: 5px;
            margin-right: 12px;
            accent-color: var(--primary);
        }

        .terms label {
            font-size: 0.9rem;
            color: var(--text);
            line-height: 1.5;
        }

        .terms a {
            color: var(--primary);
            text-decoration: none;
            font-weight: 600;
        }

        .terms a:hover {
            text-decoration: underline;
        }

        .btn-register {
            width: 100%;
            padding: 1rem;
            border: none;
            border-radius: 12px;
            background: linear-gradient(to right, var(--primary), var(--secondary));
            color: white;
            font-size: 1.1rem;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
            box-shadow: 0 5px 15px rgba(67, 97, 238, 0.4);
            position: relative;
        }

        .btn-register:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(67, 97, 238, 0.6);
        }
        
        .btn-register.loading {
            color: transparent;
        }
        
        .btn-register.loading::after {
            content: "";
            position: absolute;
            width: 24px;
            height: 24px;
            top: 50%;
            left: 50%;
            margin: -12px 0 0 -12px;
            border: 3px solid rgba(255, 255, 255, 0.3);
            border-top: 3px solid white;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        .login-link {
            text-align: center;
            margin-top: 1.5rem;
            color: var(--text);
            font-size: 1rem;
        }

        .login-link a {
            color: var(--primary);
            text-decoration: none;
            font-weight: 600;
        }

        .login-link a:hover {
            text-decoration: underline;
        }

        .success-message {
            background: var(--success);
            color: white;
            padding: 1rem;
            border-radius: 10px;
            text-align: center;
            margin-top: 1.5rem;
            display: none;
            animation: fadeIn 0.5s ease;
        }

        /* 手机号输入区域特定样式 */
        .phone-input-container {
            display: flex;
            gap: 10px;
        }
        
        .phone-prefix {
            display: flex;
            align-items: center;
            padding: 0 15px;
            background: rgba(255, 255, 255, 0.5);
            border: 1px solid #d1d9e6;
            border-radius: 12px;
            font-weight: 500;
            box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.05);
        }

        /* 动画 */
        @keyframes float {
            0% {
                transform: translateY(0px);
            }
            50% {
                transform: translateY(-15px);
            }
            100% {
                transform: translateY(0px);
            }
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .navbar {
                flex-direction: column;
                gap: 1.5rem;
            }
            
            .nav-links {
                flex-wrap: wrap;
                justify-content: center;
            }
            
            .register-header h1 {
                font-size: 2rem;
            }
            
            .register-card {
                padding: 1.5rem;
            }
        }

        @media (max-width: 576px) {
            .phone-input-container {
                flex-direction: column;
                gap: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="background-blur"></div>
    
    <header>
        <nav class="navbar glass">
            <div class="logo">
                <span class="logo-icon">✨</span>
                <span>灵犀智苑</span>
            </div>
            <ul class="nav-links">
                <li><a href="index.html">首页</a></li>
                <li><a href="design.html">AI设计</a></li>
                <li><a href="mall.html">家具商城</a></li>
                <li><a href="idea.html">灵感库</a></li>
                <li><a href="partner.html">商家合作</a></li>
            </ul>
            <div class="cta-buttons">
                <a href="login.html" class="btn btn-login glass">登录</a>
                <a href="register.html" class="btn btn-signup">免费注册</a>
            </div>
        </nav>
    </header>

    <main class="container">
        <section class="register-container">
            <div class="register-card glass">
                <div class="register-header">
                    <h1>创建账户</h1>
                    <p>加入我们，开启全新体验</p>
                </div>
                
                <form id="registerForm">
                    <div class="form-group">
                        <label for="name">用户名</label>
                        <div class="input-with-icon">
                            <i class="fas fa-user"></i>
                            <input type="text" id="name" class="form-control" placeholder="输入用户名" autocomplete="off">
                        </div>
                        <div class="error-message" id="name-error">用户名必须为3-20个字符</div>
                    </div>
                    
                    <div class="form-group">
                        <label for="email">电子邮箱</label>
                        <div class="input-with-icon">
                            <i class="fas fa-envelope"></i>
                            <input type="email" id="email" class="form-control" placeholder="输入电子邮箱">
                        </div>
                        <div class="error-message" id="email-error">请输入有效的电子邮箱地址</div>
                    </div>
                    
                    <!-- 修改后的手机号输入区域 -->
                    <div class="form-group">
                        <label for="phone">手机号</label>
                        <div class="phone-input-container">
                            <div class="phone-prefix">
                                <i class="fas fa-phone"></i> +86
                            </div>
                            <div class="input-with-icon phone-number">
                                <input type="tel" id="phone" class="form-control" placeholder="输入手机号码" style="padding-left: 15px;">
                            </div>
                        </div>
                        <div class="error-message" id="phone-error">请输入有效的手机号码</div>
                    </div>
                    
                    <div class="form-group">
                        <label for="password">密码</label>
                        <div class="input-with-icon">
                            <i class="fas fa-lock"></i>
                            <input type="password" id="password" class="form-control" placeholder="输入密码">
                        </div>
                        <div class="password-strength">
                            <div class="strength-bar" id="strength-bar-1"></div>
                            <div class="strength-bar" id="strength-bar-2"></div>
                            <div class="strength-bar" id="strength-bar-3"></div>
                            <div class="strength-bar" id="strength-bar-4"></div>
                        </div>
                        <div class="strength-text" id="strength-text">密码强度：弱</div>
                        <div class="error-message" id="password-error">密码必须至少8个字符，包含字母和数字</div>
                    </div>
                    
                    <div class="form-group">
                        <label for="confirm-password">确认密码</label>
                        <div class="input-with-icon">
                            <i class="fas fa-lock"></i>
                            <input type="password" id="confirm-password" class="form-control" placeholder="再次输入密码">
                        </div>
                        <div class="error-message" id="confirm-password-error">两次输入的密码不一致</div>
                    </div>
                    
                    <div class="terms">
                        <input type="checkbox" id="terms">
                        <label for="terms">我已阅读并同意<a href="#">服务条款</a>和<a href="#">隐私政策</a></label>
                    </div>
                    
                    <button type="submit" class="btn-register">注册账户</button>
                    
                    <div class="success-message" id="success-message">
                        <i class="fas fa-check-circle"></i> 注册成功！正在跳转...
                    </div>
                </form>
                
                <div class="login-link">
                    已有账户？<a href="login.html">立即登录</a>
                </div>
            </div>
        </section>
    </main>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const form = document.getElementById('registerForm');
            const passwordInput = document.getElementById('password');
            const confirmPasswordInput = document.getElementById('confirm-password');
            const strengthBars = document.querySelectorAll('.strength-bar');
            const strengthText = document.getElementById('strength-text');
            const phoneInput = document.getElementById('phone');
            const registerButton = document.querySelector('.btn-register');
            const successMessage = document.getElementById('success-message');
            
            // 设置API基础URL（根据要求修改）
            const API_BASE_URL = 'http://localhost:8088/another';
            
            // 密码强度检测
            passwordInput.addEventListener('input', function() {
                const password = passwordInput.value;
                let strength = 0;
                
                // 长度检查
                if (password.length >= 8) strength += 1;
                if (password.length >= 12) strength += 1;
                
                // 包含数字
                if (/\d/.test(password)) strength += 1;
                
                // 包含大写字母
                if (/[A-Z]/.test(password)) strength += 1;
                
                // 包含特殊字符
                if (/[^A-Za-z0-9]/.test(password)) strength += 1;
                
                // 更新强度条
                strengthBars.forEach((bar, index) => {
                    if (index < strength) {
                        bar.style.background = getStrengthColor(strength);
                    } else {
                        bar.style.background = '#e9ecef';
                    }
                });
                
                // 更新文本
                const strengthLabels = ['弱', '一般', '中等', '强', '非常强'];
                strengthText.textContent = `密码强度：${strengthLabels[strength - 1] || '弱'}`;
                strengthText.style.color = getStrengthColor(strength);
            });
            
            function getStrengthColor(strength) {
                const colors = ['#e74c3c', '#f39c12', '#3498db', '#2ecc71', '#27ae60'];
                return colors[strength - 1] || '#e74c3c';
            }
            
            // 表单验证
            form.addEventListener('submit', async function(e) {
                e.preventDefault();
                let isValid = true;
                
                // 清除所有错误信息
                document.querySelectorAll('.error-message').forEach(el => {
                    el.style.display = 'none';
                });
                
                // 用户名验证
                const name = document.getElementById('name').value;
                const nameError = document.getElementById('name-error');
                if (name.length < 3 || name.length > 20) {
                    nameError.style.display = 'block';
                    isValid = false;
                }
                
                // 邮箱验证
                const email = document.getElementById('email').value;
                const emailError = document.getElementById('email-error');
                const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
                if (!emailRegex.test(email)) {
                    emailError.style.display = 'block';
                    isValid = false;
                }
                
                // 手机号验证
                const phone = phoneInput.value;
                const phoneError = document.getElementById('phone-error');
                const phoneRegex = /^1[3-9]\d{9}$/;
                if (!phoneRegex.test(phone)) {
                    phoneError.style.display = 'block';
                    isValid = false;
                }
                
                // 密码验证
                const password = passwordInput.value;
                const passwordError = document.getElementById('password-error');
                if (password.length < 8 || !/\d/.test(password) || !/[a-zA-Z]/.test(password)) {
                    passwordError.style.display = 'block';
                    isValid = false;
                }
                
                // 确认密码验证
                const confirmPassword = confirmPasswordInput.value;
                const confirmPasswordError = document.getElementById('confirm-password-error');
                if (password !== confirmPassword) {
                    confirmPasswordError.style.display = 'block';
                    isValid = false;
                }
                
                // 条款同意验证
                const terms = document.getElementById('terms');
                if (!terms.checked) {
                    alert('请阅读并同意服务条款和隐私政策');
                    isValid = false;
                }
                
                // 如果验证通过，发送注册请求
                if (isValid) {
                    const registerData = {
                        name: name,
                        password: password,
                        email: email,
                        phone: phone
                    };
                    
                    // 显示加载状态
                    registerButton.classList.add('loading');
                    registerButton.disabled = true;
                    
                    try {
                        const response = await fetch(`${API_BASE_URL}/user/user/register`, {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json'
                            },
                            body: JSON.stringify(registerData)
                        });
                        
                        const data = await response.json();
                        
                        if (data.code === 1) { // 修改为判断code为1表示成功
                            successMessage.style.display = 'block';
                            
                            setTimeout(function() {
                                form.reset();
                                terms.checked = false;
                                
                                // 重置密码强度显示
                                strengthBars.forEach(bar => {
                                    bar.style.background = '#e9ecef';
                                });
                                strengthText.textContent = '密码强度：弱';
                                strengthText.style.color = '#6c757d';
                                
                                // 跳转到登录页面
                                window.location.href = 'login.html';
                            }, 2000);
                        } else {
                            // 显示具体错误信息
                            const errorMsg = data.msg || '注册失败，请稍后重试';
                            alert(`注册失败: ${errorMsg}`);
                        }
                    } catch (error) {
                        console.error('注册请求错误:', error);
                        alert('网络请求失败，请检查连接或稍后重试');
                    } finally {
                        // 重置按钮状态
                        registerButton.classList.remove('loading');
                        registerButton.disabled = false;
                    }
                }
            });
            
            // 实时密码匹配检查
            confirmPasswordInput.addEventListener('input', function() {
                const password = passwordInput.value;
                const confirmPassword = confirmPasswordInput.value;
                const confirmPasswordError = document.getElementById('confirm-password-error');
                
                if (password !== confirmPassword && confirmPassword.length > 0) {
                    confirmPasswordError.style.display = 'block';
                } else {
                    confirmPasswordError.style.display = 'none';
                }
            });
            
            // 实时手机号验证
            phoneInput.addEventListener('input', function() {
                const phone = phoneInput.value;
                const phoneError = document.getElementById('phone-error');
                const phoneRegex = /^1[3-9]\d{9}$/;
                
                if (!phoneRegex.test(phone) && phone.length > 0) {
                    phoneError.style.display = 'block';
                } else {
                    phoneError.style.display = 'none';
                }
            });
        });
    </script>
</body>
</html>